package com.example.park_2306.adapter

import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.DateEntity
import com.example.base.utils.DateTimeUtils
import com.example.park_2306.R
import com.example.park_2306.databinding.ItemDateBinding
import java.util.Calendar
import java.util.Date

class DateAdapter:BaseQuickAdapter<DateEntity,BaseViewHolder>(R.layout.item_date) {
    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemDateBinding>(viewHolder.itemView)
    }
    override fun convert(helper: BaseViewHolder, item: DateEntity) {
        val binding = DataBindingUtil.getBinding<ItemDateBinding>(helper.itemView)
        binding?.dateContent?.text = DateTimeUtils.getDate(item.content as Date)//日期

        val calendar = Calendar.getInstance()
        calendar.time = Date()
        calendar.add(Calendar.DAY_OF_MONTH,1)
        if(DateTimeUtils.getDate(item.content as Date)==DateTimeUtils.getDate(Date())){
            binding?.dateWeek?.text = "今天"
        }else if(DateTimeUtils.getDate(item.content as Date)==DateTimeUtils.getDate(calendar.time)){
            binding?.dateWeek?.text = "明天"
        }else{
            binding?.dateWeek?.text = DateTimeUtils.getWeek(item.content as Date)
        }



        if(item.isChecked){
            binding?.dateLl?.setBackgroundResource(com.example.base.R.drawable.bg_item)
        }else{
            binding?.dateLl?.background = null
        }
    }
}